import { get, post, put, del } from '@/utils/request'

export interface HellSoul {
  id: string
  name: string
  gender: 'male' | 'female'
  age: number
  crime: string
  duration: number
  imprisonTime: string
  status: 'punishing' | 'repenting' | 'completed'
}

export interface Hell {
  id: string
  name: string
  manager: string
  status: 'active' | 'maintenance' | 'full'
  capacity: number
  currentCount: number
  description: string
  punishment: string
  remarks: string
  souls: HellSoul[]
}

export interface HellParams {
  keyword?: string
  status?: string
  startTime?: string
  endTime?: string
  page: number
  pageSize: number
}

export interface HellStats {
  total: number
  active: number
  maintenance: number
  full: number
  totalCapacity: number
  totalCurrentCount: number
}

export interface CreateHellParams {
  name: string
  manager: string
  capacity: number
  description: string
  punishment: string
  remarks?: string
}

export interface UpdateHellParams {
  name?: string
  manager?: string
  capacity?: number
  description?: string
  punishment?: string
  remarks?: string
  status?: 'active' | 'maintenance' | 'full'
}

export interface AddSoulParams {
  soulId: string
  crime: string
  duration: number
}

const HellAPI = {
  list: '/api/hells',
  stats: '/api/hells/stats',
  create: '/api/hells',
  get: (id: string) => `/api/hells/${id}`,
  update: (id: string) => `/api/hells/${id}`,
  delete: (id: string) => `/api/hells/${id}`,
  souls: {
    add: (id: string) => `/api/hells/${id}/souls`,
    remove: (id: string, soulId: string) => `/api/hells/${id}/souls/${soulId}`,
  },
}

export const HellService = {
  async getHells(params: HellParams) {
    return get<{ total: number; items: Hell[] }>(HellAPI.list, params)
  },

  async getHell(id: string) {
    return get<Hell>(HellAPI.get(id))
  },

  async getStats() {
    return get<HellStats>(HellAPI.stats)
  },

  async createHell(params: CreateHellParams) {
    return post<Hell>(HellAPI.create, params)
  },

  async updateHell(id: string, params: UpdateHellParams) {
    return put<Hell>(HellAPI.update(id), params)
  },

  async deleteHell(id: string) {
    return del(HellAPI.delete(id))
  },

  async addSoul(id: string, params: AddSoulParams) {
    return post<HellSoul>(HellAPI.souls.add(id), params)
  },

  async removeSoul(id: string, soulId: string) {
    return del(HellAPI.souls.remove(id, soulId))
  },
}
